public class Main {

        public static int removeElement(int[] nums, int val) {
            int size = nums.length;
            for(int i = 0;i<size;i++){
                if(nums[i] == val && nums[size-1] == val) {
                    size--;
                }
                    for(int j = size; j>=0;j--){
                        if(nums[size-1] != val)
                            break;
                        size--;
                        if(size<=0)
                            return 0;
                        if(size == 1 && nums[size-1] != val)
                            return 1;
                    }

                if(nums[i] == val){
                    nums[i] = nums[size-1];
                    nums[size-1] = val;
                    size--;
                }
            }
            return size;
        }

        public static void main(String[] args) {
            int[]array = new int[]{4,1,2,4,4,0,0};
            int ret = removeElement(array,4);
            System.out.println(ret);
        }



}
